From a5f7c420940df72f613dbffec088ca703921d43d Mon Sep 17 00:00:00 2001 From: Alastair Tse Date: Thu, 26 Oct 2006 17:59:49 +0100 Subject: [PATCH] [XEND] Add more API implementations, add sched_id_get to xc. Signed-off-by: Alastair Tse --- tools/python/xen/lowlevel/xc/xc.c | 20 +++++++++++++++++++ tools/python/xen/xend/XendAPI.py | 10 +++++----- tools/python/xen/xend/XendDomainInfo.py | 8 +++++++- .../python/xen/xend/XendStorageRepository.py | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index e116972640..5de0f06657 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -647,6 +647,15 @@ static PyObject *pyxc_shadow_mem_control(PyObject *self, return Py_BuildValue("i", mbarg); } +static PyObject *pyxc_sched_id_get(XcObject *self) { + + int sched_id; + if (xc_sched_id(self->xc_handle, &sched_id) != 0) + return PyErr_SetFromErrno(xc_error); + + return Py_BuildValue("i", sched_id); +} + static PyObject *pyxc_sched_credit_domain_set(XcObject *self, PyObject *args, PyObject *kwds) @@ -976,6 +985,12 @@ static PyMethodDef pyxc_methods[] = { " vcpus [int, 1]: Number of Virtual CPUS in domain.\n\n" "Returns: [int] 0 on success; -1 on error.\n" }, + { "sched_id_get", + (PyCFunction)pyxc_sched_id_get, + METH_NOARGS, "\n" + "Get the current scheduler type in use.\n" + "Returns: [int] sched_id.\n" }, + { "sedf_domain_set", (PyCFunction)pyxc_sedf_domain_set, METH_KEYWORDS, "\n" @@ -1242,6 +1257,11 @@ PyMODINIT_FUNC initxc(void) Py_INCREF(xc_error); PyModule_AddObject(m, "Error", xc_error); + + /* Expose some libxc constants to Python */ + PyModule_AddIntConstant(m, "XEN_SCHEDULER_SEDF", XEN_SCHEDULER_SEDF); + PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT); + } diff --git a/tools/python/xen/xend/XendAPI.py b/tools/python/xen/xend/XendAPI.py index 895da5256b..077ceefddf 100644 --- a/tools/python/xen/xend/XendAPI.py +++ b/tools/python/xen/xend/XendAPI.py @@ -701,23 +701,23 @@ class XendAPI: def vm_get_actions_after_shutdown(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) - return xen_api_success('') + return xen_api_success(dom.get_on_shutdown()) def vm_get_actions_after_reboot(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) - return xen_api_success('') + return xen_api_success(dom.get_on_reboot()) def vm_get_actions_after_suspend(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) - return xen_api_success('') + return xen_api_success(dom.get_on_suspend()) def vm_get_actions_after_crash(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) - return xen_api_success('') + return xen_api_success(dom.get_on_crash()) def vm_get_bios_boot(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) - return xen_api_success('') + return xen_api_success(dom.get_bios_boot()) def vm_get_platform_std_vga(self, session, vm_ref): dom = XendDomain.instance().get_vm_by_uuid(vm_ref) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index af774cf303..8f677ae30b 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -1655,7 +1655,13 @@ class XendDomainInfo: def get_memory_static_min(self): return self.info['memory'] def get_vcpus_policy(self): - return '' # TODO + sched_id = xc.sched_id_get() + if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF: + return 'sedf' + elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT: + return 'credit' + else: + return 'unknown' def get_vcpus_params(self): return '' # TODO def get_power_state(self): diff --git a/tools/python/xen/xend/XendStorageRepository.py b/tools/python/xen/xend/XendStorageRepository.py index 003a38f3e9..c2fbdb1294 100644 --- a/tools/python/xen/xend/XendStorageRepository.py +++ b/tools/python/xen/xend/XendStorageRepository.py @@ -100,6 +100,7 @@ class XendStorageRepository: """ self.lock.acquire() try: + # create directory if /var/lib/xend/storage does not exist if not os.path.exists(XEND_STORAGE_DIR): os.makedirs(XEND_STORAGE_DIR) os.chmod(XEND_STORAGE_DIR, 0700) @@ -111,6 +112,8 @@ class XendStorageRepository: if filename[-5:] == XEND_STORAGE_QCOW_FILENAME[-5:]: image_uuid = filename[:-5] seen_images.append(image_uuid) + + # add this image if we haven't seen it before if image_uuid not in self.images: qcow_file = XEND_STORAGE_QCOW_FILENAME % image_uuid cfg_file = XEND_STORAGE_VDICFG_FILENAME % image_uuid -- 2.30.2